#!/bin/sh

# A script to replace the full text of the MIT license with a reference to the
# license URL. Saved for posterity.
#
# TODO: also add support for C++ style versions

REPLACELINE=" \* Permission is hereby granted, free of charge, to any person obtaining\n"\
" \* a copy of this software and associated documentation files\n"\
" \* \(the \"Software\"\), to deal in the Software without restriction,\n"\
" \* including without limitation the rights to use, copy, modify, merge,\n"\
" \* publish, distribute, sublicense, and\/or sell copies of the Software,\n"\
" \* and to permit persons to whom the Software is furnished to do so,\n"\
" \* subject to the following conditions:\n"\
" \*\n"\
" \* The above copyright notice and this permission notice shall be\n"\
" \* included in all copies or substantial portions of the Software.\n"\
" \*\n"\
" \* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n"\
" \* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n"\
" \* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n"\
" \* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n"\
" \* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n"\
" \* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n"\
" \* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"

REPLACEWITH=" \* Use of this source code is governed by a MIT-style\n"\
" \* license that can be found in the LICENSE file or at\n"\
" \* https:\/\/opensource.org\/licenses\/MIT\n"

FILES=$(find . -name *.[chS] -or -name \*.cpp | grep -v external | grep -v build-)
echo $FILES

for f in $FILES; do
    echo $f
    perl -0777 -pi -e "s/${REPLACELINE}/${REPLACEWITH}/g" $f
done

